package com.arvin.service.serviceImpl;

import com.arvin.mapper.LinkMapper;
import com.arvin.pojo.Link;
import com.arvin.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author tengyue
 * @date 2023/12/5/18:02
 */
@Service
public class LinkServiceImpl implements LinkService {

    @Autowired
    private LinkMapper linkMapper;

    /**
     * 根据链接主题获取链接信息
     * @param linkName
     * @return
     */
    @Override
    public List<Link> getLinkInfo(String linkName) {
        return linkMapper.getLinkInfo(linkName);
    }

    /**
     * 根据id删除链接
     * @param linkId
     */
    @Override
    public void deleteLinkById(Integer linkId) {
        linkMapper.deleteLinkById(linkId);
    }

    /**
     * 根据id获取链接
     * @param linkId
     * @return
     */
    @Override
    public Link getLinkById(Integer linkId) {
        return linkMapper.getLinkById(linkId);
    }

    /**
     * 编辑链接
     * @param link
     */
    @Override
    public void updateLink(Link link) {
        link.setUpdateTime(LocalDateTime.now());
        linkMapper.updateLink(link);
    }

    /**
     * 添加链接
     * @param link
     */
    @Override
    public void addLink(Link link) {
        link.setCreateTime(LocalDateTime.now());
        link.setUpdateTime(LocalDateTime.now());
        linkMapper.insertLink(link);
    }
}
